/**
 * @param {number[]} nums
 * @param {number} goal
 * @return {number}
 */
var numSubarraysWithSum = function (nums, goal) {
  let left = 0,
    right,
    count=0,
    sum = 0
  while (left < nums.length) {
    right=left
    sum=0
    while (right < nums.length + 1) {
      sum += nums[right]
      if (sum == goal) {
        count++
      } else if (sum > goal) {
        break
      }
      right++
    }

    left++
  }
  return count
}
numSubarraysWithSum([0,0,0,0,0],0)